
    ##########################################################################################
    ### R code for Figure 2 in Supplemental Files
    ### : Compute the Vote Margins of ADA-selected votes and all foreign policy votes
    ##########################################################################################

    ### Compute ADA 1993 and 1994 vote margins
    ADA <- read.csv("Supplemental_Figure_2_Data1.csv")  # This dataset is ADA_1993_94_Vote_Margins
    n.ADA <- nrow(ADA)

    ADA.margins <- rep(NA, n.ADA) 
    for(i in 1:n.ADA){    
    ADA.margins[i] <- max(ADA$n.Yea[i], ADA$n.Nay[i])/sum(ADA$n.Yea[i], ADA$n.Nay[i])
    }
    
    ### Compute vote margins of all foreign policy votes in 1993 and 1994 (103rd House)
    All.FP <- read.csv("Supplemental_Figure_2_Data2.csv", header=T) # This is FP votes data for the 103rd House

    n.row <- nrow(All.FP)
    n.col <- ncol(All.FP)
    n.vote <- n.col - 5
    
    Bills <- All.FP[,-c(1:5)]
    
    ## calculate vote margins

    margin <- apply(Bills,2,
                    function(x){
                    ok <- !is.na(x)
                    z <- c(sum(x[ok]==0),sum(x[ok]==1))
                    z
                    }
                    )
    margin <- t(margin)

    All.margins <- rep(NA, n.vote) 
    for(i in 1:n.vote){    
    All.margins[i] <- max(margin[i,1], margin[i,2])/sum(margin[i,1], margin[i,2])
    }

    postscript("Supplemental_Figure2.eps", height=10, width=6, horizontal=F)
    par(mfrow=c(2,1))
    hist(100*All.margins, main="All Foreign Policy Votes", xlab="", xlim=c(50, 100))
    hist(100*ADA.margins, main="ADA-Selected Votes", xlab="", xlim=c(50, 100))
    dev.off()


